home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / BrickoidDemo / BrickoidDemoGeneric.jar / arka / Displayable2.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-09-10  |  6.5 KB  |  312 lines

  1. package arka;
  2.  
  3. import java.io.IOException;
  4. import javax.microedition.lcdui.Canvas;
  5. import javax.microedition.lcdui.Font;
  6. import javax.microedition.lcdui.Graphics;
  7. import javax.microedition.lcdui.Image;
  8.  
  9. public class Displayable2 extends Canvas {
  10.    Image dbimage;
  11.    Image dbimage1;
  12.    Image background;
  13.    Image ball;
  14.    Image board;
  15.    Image stick;
  16.    Image dust;
  17.    Image die;
  18.    Image die2;
  19.    Image pause;
  20.    Image soundim;
  21.    Image ico;
  22.    Image[] fly = new Image[13];
  23.    Graphics dbg;
  24.    Graphics dbg1;
  25.    Image[] brick = new Image[5];
  26.    Image[] number = new Image[10];
  27.    int di1;
  28.    int di2;
  29.    int di3;
  30.    // $FF: renamed from: bx int
  31.    int field_0;
  32.    // $FF: renamed from: by int
  33.    int field_1;
  34.    int bmovex;
  35.    int bmovey;
  36.    // $FF: renamed from: f1 int
  37.    int field_2;
  38.    int fx1;
  39.    int fy1;
  40.    int fmovex1;
  41.    int fmovey1;
  42.    int dx1;
  43.    int dy1;
  44.    // $FF: renamed from: f2 int
  45.    int field_3;
  46.    int fx2;
  47.    int fy2;
  48.    int fmovex2;
  49.    int fmovey2;
  50.    int dx2;
  51.    int dy2;
  52.    // $FF: renamed from: f3 int
  53.    int field_4;
  54.    int fx3;
  55.    int fy3;
  56.    int fmovex3;
  57.    int fmovey3;
  58.    int dx3;
  59.    int dy3;
  60.    // $FF: renamed from: sy int
  61.    int field_5;
  62.    int smovey;
  63.    int score;
  64.    int lives;
  65.    int level;
  66.    int bricks;
  67.    int cx1;
  68.    int cy1;
  69.    int cx2;
  70.    int cy2;
  71.    int cr1;
  72.    int cr2;
  73.    boolean crash1;
  74.    boolean crash2;
  75.    boolean newlevel;
  76.    boolean death1;
  77.    boolean death2;
  78.    boolean death3;
  79.    boolean dieing1;
  80.    boolean dieing2;
  81.    boolean dieing3;
  82.    boolean paused;
  83.  
  84.    public Displayable2() {
  85.       try {
  86.          this.jbInit();
  87.       } catch (Exception e) {
  88.          ((Throwable)e).printStackTrace();
  89.       }
  90.  
  91.    }
  92.  
  93.    private void jbInit() throws Exception {
  94.       try {
  95.          this.background = Image.createImage("/arka/arkanoid.png");
  96.          this.ball = Image.createImage("/arka/ball.png");
  97.          this.board = Image.createImage("/arka/board.png");
  98.          this.stick = Image.createImage("/arka/stick.png");
  99.          this.dust = Image.createImage("/arka/dust.png");
  100.          this.die = Image.createImage("/arka/die.png");
  101.          this.die2 = Image.createImage("/arka/die2.png");
  102.          this.pause = Image.createImage("/arka/pause.png");
  103.          this.soundim = Image.createImage("/arka/sound.png");
  104.          this.brick[0] = Image.createImage("/arka/brick0.png");
  105.          this.brick[1] = Image.createImage("/arka/brick1.png");
  106.          this.brick[2] = Image.createImage("/arka/brick2.png");
  107.          this.brick[3] = Image.createImage("/arka/brick3.png");
  108.          this.number[0] = Image.createImage("/arka/0.png");
  109.          this.number[1] = Image.createImage("/arka/1.png");
  110.          this.number[2] = Image.createImage("/arka/2.png");
  111.          this.number[3] = Image.createImage("/arka/3.png");
  112.          this.number[4] = Image.createImage("/arka/4.png");
  113.          this.number[5] = Image.createImage("/arka/5.png");
  114.          this.number[6] = Image.createImage("/arka/6.png");
  115.          this.number[7] = Image.createImage("/arka/7.png");
  116.          this.number[8] = Image.createImage("/arka/8.png");
  117.          this.number[9] = Image.createImage("/arka/9.png");
  118.          this.fly[0] = Image.createImage("/arka/fly0.png");
  119.          this.fly[1] = Image.createImage("/arka/fly1.png");
  120.          this.fly[2] = Image.createImage("/arka/fly2.png");
  121.          this.fly[3] = Image.createImage("/arka/fly3.png");
  122.          this.fly[4] = Image.createImage("/arka/fly4.png");
  123.          this.fly[5] = Image.createImage("/arka/fly6.png");
  124.          this.fly[6] = Image.createImage("/arka/fly5.png");
  125.          this.fly[7] = Image.createImage("/arka/fly6.png");
  126.          this.fly[8] = Image.createImage("/arka/fly7.png");
  127.          this.fly[9] = Image.createImage("/arka/fly8.png");
  128.          this.fly[10] = Image.createImage("/arka/fly7.png");
  129.          this.fly[11] = Image.createImage("/arka/fly9.png");
  130.          this.fly[12] = Image.createImage("/arka/fly10.png");
  131.          this.ico = Image.createImage("/arka/ico.png");
  132.       } catch (IOException e) {
  133.          System.out.println(((Throwable)e).getMessage());
  134.       }
  135.  
  136.       this.cr1 = 0;
  137.       this.cr2 = 0;
  138.       this.smovey = 0;
  139.       this.field_0 = 10;
  140.       this.field_1 = 10;
  141.       this.bmovex = 1;
  142.       this.bmovey = 1;
  143.       this.di1 = 0;
  144.       this.di2 = 0;
  145.       this.di3 = 0;
  146.       this.score = 0;
  147.       this.lives = 3;
  148.       this.level = 1;
  149.       this.field_2 = 0;
  150.       this.field_3 = 0;
  151.       this.crash1 = false;
  152.       this.crash2 = false;
  153.       this.newlevel = false;
  154.       this.dieing1 = false;
  155.       this.dieing2 = false;
  156.       this.dieing3 = false;
  157.       this.paused = false;
  158.       this.dbimage1 = Image.createImage(96, 64);
  159.       this.dbg1 = this.dbimage1.getGraphics();
  160.       this.dbg1.setColor(255, 255, 255);
  161.       Font.getFont(0, 0, 8);
  162.    }
  163.  
  164.    protected void keyPressed(int keyCode) {
  165.       if (keyCode == -1 || keyCode == 49 || keyCode == 50) {
  166.          this.smovey = -2;
  167.       }
  168.  
  169.       if (keyCode == -2 || keyCode == 51 || keyCode == 53) {
  170.          this.smovey = 2;
  171.       }
  172.  
  173.       if (this.bmovex == 0) {
  174.          this.bmovex = -1;
  175.          if (this.smovey != 0) {
  176.             this.bmovey = this.smovey / 2;
  177.          } else {
  178.             this.bmovey = 1;
  179.          }
  180.       }
  181.  
  182.       if (keyCode == 48) {
  183.          MIDlet1.pauseGame();
  184.       }
  185.  
  186.       if (keyCode == 56) {
  187.          if (this.paused) {
  188.             this.paused = false;
  189.          } else {
  190.             this.paused = true;
  191.          }
  192.       }
  193.  
  194.    }
  195.  
  196.    protected void keyReleased(int keyCode) {
  197.       if (keyCode == -1 || keyCode == 49 || keyCode == 50) {
  198.          this.smovey = 0;
  199.       }
  200.  
  201.       if (keyCode == -2 || keyCode == 51 || keyCode == 53) {
  202.          this.smovey = 0;
  203.       }
  204.  
  205.    }
  206.  
  207.    protected void paint(Graphics g) {
  208.       if (this.crash1) {
  209.          ++this.cr1;
  210.          this.dbg1.drawImage(this.dust, this.cx1, this.cy1, 20);
  211.          if (this.cr1 > 2) {
  212.             this.cr1 = 0;
  213.             this.score += 10;
  214.             this.crash1 = false;
  215.             this.dbg1.fillRect(this.cx1, this.cy1, 5, 4);
  216.             --this.bricks;
  217.             if (this.bricks == 0) {
  218.                ++this.level;
  219.                this.newlevel = true;
  220.             }
  221.          }
  222.       }
  223.  
  224.       if (this.crash2) {
  225.          ++this.cr2;
  226.          this.dbg1.drawImage(this.dust, this.cx2, this.cy2, 20);
  227.          if (this.cr2 > 2) {
  228.             this.cr2 = 0;
  229.             this.score += 10;
  230.             this.crash2 = false;
  231.             this.dbg1.fillRect(this.cx2, this.cy2, 5, 4);
  232.             --this.bricks;
  233.             if (this.bricks == 0) {
  234.                ++this.level;
  235.                this.newlevel = true;
  236.             }
  237.          }
  238.       }
  239.  
  240.       g.drawImage(this.dbimage1, 0, 0, 20);
  241.       g.drawImage(this.stick, 89, this.field_5, 20);
  242.       g.drawImage(this.ball, this.field_0 - 2, this.field_1 - 1, 20);
  243.       if (!this.death1) {
  244.          g.drawImage(this.fly[this.field_2], this.fx1 - 2, this.fy1 - 2, 20);
  245.       }
  246.  
  247.       if (this.dieing1) {
  248.          ++this.di1;
  249.          if (this.di1 < 4) {
  250.             g.drawImage(this.die, this.fx1 - 3, this.fy1 - 3, 20);
  251.          } else {
  252.             g.drawImage(this.die2, this.fx1 - 3, this.fy1 - 3, 20);
  253.          }
  254.  
  255.          if (this.di1 > 7) {
  256.             this.di1 = 0;
  257.             this.dieing1 = false;
  258.          }
  259.       }
  260.  
  261.       if (!this.death2) {
  262.          g.drawImage(this.fly[this.field_3 + 5], this.fx2 - 2, this.fy2 - 2, 20);
  263.       }
  264.  
  265.       if (this.dieing2) {
  266.          ++this.di2;
  267.          if (this.di2 < 4) {
  268.             g.drawImage(this.die, this.fx2 - 3, this.fy2 - 3, 20);
  269.          } else {
  270.             g.drawImage(this.die2, this.fx2 - 3, this.fy2 - 3, 20);
  271.          }
  272.  
  273.          if (this.di2 > 7) {
  274.             this.di2 = 0;
  275.             this.dieing2 = false;
  276.          }
  277.       }
  278.  
  279.       if (!this.death3) {
  280.          g.drawImage(this.fly[this.field_4 + 11], this.fx3 - 2, this.fy3 - 2, 20);
  281.       }
  282.  
  283.       if (this.dieing3) {
  284.          ++this.di3;
  285.          if (this.di3 < 4) {
  286.             g.drawImage(this.die, this.fx3 - 3, this.fy3 - 3, 20);
  287.          } else {
  288.             g.drawImage(this.die2, this.fx3 - 3, this.fy3 - 3, 20);
  289.          }
  290.  
  291.          if (this.di3 > 7) {
  292.             this.di3 = 0;
  293.             this.dieing3 = false;
  294.          }
  295.       }
  296.  
  297.       g.drawImage(this.board, 9, 56, 20);
  298.       g.drawImage(this.number[0], 77, 58, 20);
  299.       g.drawImage(this.number[this.score / 10 - this.score / 100 * 10], 72, 58, 20);
  300.       g.drawImage(this.number[this.score / 100 - this.score / 1000 * 10], 67, 58, 20);
  301.       g.drawImage(this.number[this.score / 1000 - this.score / 10000 * 10], 62, 58, 20);
  302.       g.drawImage(this.number[this.score / 10000 - this.score / 100000 * 10], 57, 58, 20);
  303.       g.drawImage(this.number[this.lives], 41, 58, 20);
  304.       g.drawImage(this.number[this.level / 10 - this.level / 100 * 10], 18, 58, 20);
  305.       g.drawImage(this.number[this.level - this.level / 10], 23, 58, 20);
  306.       if (this.paused) {
  307.          g.drawImage(this.pause, 28, 25, 20);
  308.       }
  309.  
  310.    }
  311. }
  312.